package com.winsomely.leecode;

/**
 * 字符串中的单词数
 * 
 * @author liujiawei
 *
 */
public class CountSegments {

	public int countSegments(String s) {
		if (s.length() == 0) {
			return 0;
		}
		boolean isBegin = false;
		int sl = 0;
		for (int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			if (c != ' ' && isBegin == false) {
				isBegin = true;
				sl++;
			} else if (c == ' ') {
				isBegin = false;
			}
		}
		return sl;
	}

	public static void main(String[] args) {
		CountSegments t = new CountSegments();
		String s = "h";
		System.out.println(t.countSegments(s));
	}

}
